﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LikeUs.WebService.Client;
using LikeUs.WebService.Client.WSInfoClient;
using System.Data;

namespace LikeUsWebSite
{
    public partial class Community : System.Web.UI.Page
    {
        public float maxvalue;
        protected void Page_Load(object sender, EventArgs e)
        {
            getFriends();
        }

        protected void getFriends()
        {
            DataTable dt;
            WSInfoProxy wsProxy = new WSInfoProxy();
            //DataGrid1.DataSource = wsProxy.GetAllMyFriends(Int32.Parse(userId.Text.ToString()));
            //Response.Write(Page.User.Identity.Name);
            //UserData user = wsProxy.GetMyUser(Page.User.Identity.Name);
            UserData user = (UserData)Session["userData"];
            wsProxy.userRelationsRoutine(user);
            dt = wsProxy.GetAllMyFriends(user.UserID);
            if (dt.Rows.Count > 0)
                maxvalue = float.Parse(dt.Rows[dt.Rows.Count - 1]["distance"].ToString());
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["distance"] = Math.Round((1-(float)dt.Rows[i]["distance"]/maxvalue)*100);
            }
                DataGrid1.DataSource = dt;
            //DataGrid1.DataSource = wsProxy.GetAllMyFriendsbyName();
            DataGrid1.DataBind();
        }
    }
}
